// src/router/routes.ts

import React from "react";
import { lazy } from "react";
import {
  HomeOutlined,
  UserOutlined,
  LockOutlined,
  SettingOutlined,
} from "@ant-design/icons";

/**
 * 静态路由：无需登录即可访问
 */
export const constantRoutes: ReactRouterDOM.RouteObject[] = [
  {
    path: "/login",
    element: lazy(() => import("@pages/Login")), // 异步加载登录页
    meta: {
      title: "登录",
      hidden: true, // 不出现在菜单中
    },
  },
  {
    path: "/404",
    element: lazy(() => import("@pages/NotFound")),
    meta: {
      title: "404",
      hidden: true,
    },
  },
];

// src/router/routes.ts （续）

/**
 * 异步路由：需登录后可访问，根据角色动态过滤
 */
export const asyncRoutes: ReactRouterDOM.RouteObject[] = [
  {
    path: "/",
    element: lazy(() => import("@layouts/BasicLayout")), // 基础布局（含侧边栏、头部）
    meta: {
      requiresAuth: true,
      title: "后台首页",
    },
    children: [
      {
        path: "/",
        element: lazy(() => import("@pages/Dashboard")),
        meta: {
          title: "仪表盘",
          icon: <HomeOutlined />,
          requiresAuth: true,
        },
      },
      {
        path: "/user",
        element: lazy(() => import("@layouts/BlankLayout")), // 可套空白布局再包子路由
        meta: {
          title: "用户管理",
          icon: <UserOutlined />,
          requiresAuth: true,
          roles: ["admin", "manager"], // 只有 admin 和 manager 才能访问
        },
        children: [
          {
            path: "/user/list",
            element: lazy(() => import("@pages/User/index")),
            meta: {
              title: "用户列表",
              requiresAuth: true,
              roles: ["admin", "manager"],
            },
          },
          {
            path: "/user/create",
            element: lazy(() => import("@pages/User/create")),
            meta: {
              title: "创建用户",
              requiresAuth: true,
              roles: ["admin"],
            },
          },
          {
            path: "/user/edit/:id",
            element: lazy(() => import("@pages/User/edit")),
            meta: {
              title: "编辑用户",
              requiresAuth: true,
              roles: ["admin"],
              hidden: true, // 不在菜单中展示
            },
          },
        ],
      },
      {
        path: "/permission",
        element: lazy(() => import("@pages/Permission/index")),
        meta: {
          title: "权限管理",
          icon: <LockOutlined />,
          requiresAuth: true,
          roles: ["admin"], // 只有 admin 能访问
        },
      },
      {
        path: "/settings",
        element: lazy(() => import("@pages/Settings/index")),
        meta: {
          title: "个人设置",
          icon: <SettingOutlined />,
          requiresAuth: true,
        },
      },
      {
        path: "*",
        element: lazy(() => import("@pages/NotFound")),
        meta: {
          title: "404",
          hidden: true,
        },
      },
    ],
  },
];
